#ifndef SALESETMEAL_H
#define SALESETMEAL_H

#include "../saleBase.h"
#include<vector>
using std::vector;

//食物类型结构体
struct FoodType
{
    int id;//类型id
    string name;//类型名称
    vector<SaleBase*> foods;//该类型包含的所有食物
};


class SaleSetMeal:public SaleBase
{
public:
    SaleSetMeal(){
        class_type=CLASS_SALESETMEAL;
        num=1;
    }

    ~SaleSetMeal()
    {
        for(auto sel:selectFood)
            delete sel;
        for(auto foo:foodTypes)
            for(auto k:foo.foods)
                delete k;
    }

    /*
     * 获取用户选择规格重量等后的应付价格
     **/
    double getPayable(){return num*price;}


    virtual string toString()
    {
        string re = SaleBase::toString();
        re+="  *  "+QString::number(num).toStdString()+"  \n";
        for(auto sel : selectFood)
            re+="  "+sel->toString()+"  \n";
        return re;
    }

    //加载完整数据
    virtual void loadDetail(){}

    //修改数据库中当前id食物的数据
    virtual void alterInDataBase(){}

    //从数据库中删除当前食物
    virtual void delInDataBase(){}



    /*
     * 设置订单的订购数量
     **/
    void setNum(int num_){num=num_;}

    /*
     * 点餐时逐个增加每个食物类型中对应的食物
     * */
    void addSelectFood(SaleBase* food){selectFood.push_back(food);}

public:
    /*
     * 两荤一素套餐时，
     *  nums={2,1}
     * foodType={ {"荤" ,{ "牛肉","手撕鸡","叉烧"} },
     *              { "素", { "上海青","白菜"} }
     *          }
     * selectFood= { "牛肉" ,"手撕鸡" , "白菜" }
     * */
    vector<int> nums;//每个食物类型对应的数量
    vector<FoodType> foodTypes;//食物类型

protected:
    int num=1;//订购数量
    vector<SaleBase*> selectFood;
};

#endif // SALESETMEAL_H
